package com.CNMedical.web.controller.system;

import java.util.List;

import com.CNMedical.system.domain.vo.AppletQuestionVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.CNMedical.common.annotation.Log;
import com.CNMedical.common.core.controller.BaseController;
import com.CNMedical.common.core.domain.AjaxResult;
import com.CNMedical.common.enums.BusinessType;
import com.CNMedical.system.domain.entity.AppletQuestion;
import com.CNMedical.system.service.IAppletQuestionService;
import com.CNMedical.common.core.page.TableDataInfo;

/**
 * 试题Controller
 * 
 * @author tang
 * @date 2023-03-28
 */
@RestController
@RequestMapping("/system/question")
public class AppletQuestionController extends BaseController
{
    @Autowired
    private IAppletQuestionService appletQuestionService;

    /**
     * 查询试题列表
     */
    @PreAuthorize("@ss.hasPermi('system:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletQuestion appletQuestion)
    {
        startPage();
        List<AppletQuestionVO> list = appletQuestionService.selectAppletQuestionList(appletQuestion);
        return getDataTable(list);
    }


    /**
     * 获取试题详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appletQuestionService.selectAppletQuestionById(id));
    }

    /**
     * 新增试题
     */
    @PreAuthorize("@ss.hasPermi('system:question:add')")
    @Log(title = "试题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletQuestion appletQuestion)
    {
        return toAjax(appletQuestionService.insertAppletQuestion(appletQuestion));
    }

    /**
     * 修改试题
     */
    @PreAuthorize("@ss.hasPermi('system:question:edit')")
    @Log(title = "试题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletQuestion appletQuestion)
    {
        return toAjax(appletQuestionService.updateAppletQuestion(appletQuestion));
    }

    /**
     * 删除试题
     */
    @PreAuthorize("@ss.hasPermi('system:question:remove')")
    @Log(title = "试题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(appletQuestionService.deleteAppletQuestionByIds(ids));
    }
}
